package com.fbli.service.Impl;

import com.fbli.mapper.UserMapper;
import com.fbli.pojo.Users;
import com.fbli.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Transactional
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;


    @Override
    public Users findByUserId(int userId) {
            Users user = userMapper.findByUserId(userId);
            return user;
    }

    @Override
    public Users login(Users user) {
        Users user1 = userMapper.login(user);
        return user1;
    }

    @Override
    public Users findOne(String username) {

        return userMapper.findOne(username);
    }

    @Override
    public void register(Users user) {
        BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
        user.setPassword(passwordEncoder.encode(user.getPassword()));
        userMapper.register(user);
    }

    @Override
    public Users selectPassword(String email) {
        return userMapper.selectPassword(email);
    }
}
